﻿using Learn.Infraestrutura.Attr;
using Learn.Infraestrutura.Dto.Request;
using Learn.Infraestrutura.Dto.Request.Right;
using Learn.Infraestrutura.Tools;
using Learn.Service.Interface;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using System.Security.Claims;

namespace Learning.Api.Admin.Controllers
{

    /// <summary>
    /// 这个是登录模块
    /// </summary>
    public class RightController : BaseController
    {

        private readonly IConfiguration _configuration;
        private readonly I_Right_Service _right_Service;

        public RightController(I_Right_Service right_Service, I_Login_Service login_Service, IConfiguration configuration) : base(login_Service)
        {
            _configuration = configuration;
            _right_Service = right_Service;

        }


        /// <summary>
        /// 获取用户菜单
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Authorize(Roles = "admin")]
        public IActionResult Get_User_Menus()
        {
            var user = this.Get_Curr_User();
            var result = _right_Service.Get_User_Menus(user?.Uid);
            return Ok(result);

        }

        /// <summary>
        /// 获取所有权限
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Authorize(Roles = "admin")]
        public IActionResult Get_Rights()
        {
            int isBan=0; int isPublish = 1;
            var result=_right_Service.Get_Rights(new Right_Request_Dto 
            {
                isBan=isBan,
                isPublish=isPublish
            });
            return Ok(result);
        }
        /// <summary>
        /// 获取单个权限详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [Authorize(Roles = "admin")]
        public IActionResult Get_Curr_RightDetails(string id) 
        {
            var result = _right_Service.Get_Curr_RightDetails(new Right_Request_Dto 
            {
                rid = id
            });

            return Ok(result);
        }

        /// <summary>
        /// 获取权限配置
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        [HttpGet]
        [Authorize(Roles = "admin")]
        public IActionResult Get_Right_Config(int? page = 1, int? limit = 10, string key = "") 
        {
            var result = _right_Service.Get_Right_Config(new Right_Request_Dto 
            {
                page = page??1,
                limit = limit??10,
                key = key??""
            });
            return Ok(result);
        }
    }
}
